﻿using UnityEngine;

namespace DL.Tools
{
    public abstract class PoolItemBase : MonoBehaviour, IPool
    {
        private float _maxDelayTime;
        public bool IsRecycle { get; set; }
        public bool User { get; set; }

        public float MaxDelayTime
        {
            get => _maxDelayTime;
        }

        protected virtual void Update()
        {
            RecycleObject();
        }

        #region 接口

        /// <summary>
        /// 主动回收方法
        /// </summary>
        public virtual void Recycle()
        {
            IsRecycle = true;
        }


        public virtual void SpawnObject()
        {
            IsRecycle = false;
            // GameObjectPoolSystem.Inst.TakeGameObject("Timer").GetComponent<Timer>().CreateTime(maxDelayTime,
            //     () => isRecycle = true);
        }

        public virtual void SpawnObject(Transform user)
        {
            this.User = user;
            IsRecycle = false;
            // GameObjectPoolSystem.Inst.TakeGameObject("Timer").GetComponent<Timer>().CreateTime(maxDelayTime,
            //     () => isRecycle = true);
        }

        public virtual void RecycleObject()
        {
            if (IsRecycle)
                GameObjectPoolSystem.Inst.RecyleGameObject(this.gameObject);
        }

        #endregion

    }
}
